package com.example.PriceCompare;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;

public class ResultAdapter extends BaseAdapter {
	
	private Context context;
	private List<Entry> ResultList;
	private int SelectedPosition;
	
	public ResultAdapter(Context context, List<Entry> ResultList) {
		this.context=context;
		this.ResultList=ResultList;
		this.SelectedPosition=Adapter.NO_SELECTION;
	}
	
	public int getSelectedPosition(){
		return SelectedPosition;
	}
	
	@Override
	public int getCount() {
		return ResultList.size();
		// TODO Auto-generated method stub
	}

	@Override
	public Entry getItem(int position) {
		// TODO Auto-generated method stub
		return ResultList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

		@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null){
			ItemView temp = new ItemView(context,ResultList.get(position).getProductName(),ResultList.get(position).getStoreAddress(),ResultList.get(position).getPrice(),ResultList.get(position).getDistance() );
			return temp;
		}
		else{
			((ItemView) convertView).setProductName(ResultList.get(position).getProductName());
			((ItemView) convertView).setStoreAddress(ResultList.get(position).getStoreAddress());
			((ItemView) convertView).setProductPrice(ResultList.get(position).getPrice());
			((ItemView) convertView).setStoreDistance(ResultList.get(position).getDistance());
			return convertView;
		}

	}

}
